<<<<<<< HEAD
const express = require('express')
var bodyParser = require('body-parser')

const app = express()
const port = 3000
///
app.use(express.static('www'))
///解析body中间件
app.use(bodyParser.json({ limit: '100mb' }));

app.all('*',function (req, res, next) {
    res.header('Access-Control-Allow-Origin', '*');
    res.header('Access-Control-Allow-Headers','Content-Type,token');
    res.header('Content-Type', 'application/json;charset=utf-8');
    res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS');
    next();
  });

///wx
const wxRouter = require('./wx')
wxRouter(app)

///admin
const adminRouter = require('./admin')
adminRouter(app)


app.listen(port, () => {
  console.log(`Example app listening on port ${port}`)
})




// const https = require('https')
// const express = require('express')
// var bodyParser = require('body-parser')
// const app = express()
// const port = 3000
// const SQLHelper = require('./SQLHelper')

// // let SQLHelper = require('./SQLHelper')
// SQLHelper('select * from product').then(ret => {
//     console.log('I am mysql:' ,ret);
// })


// app.use(express.static('www'))
// //解析body中间
// app.use(bodyParser.json({limit:'100mb'}));
// app.get('/wx/login', (req, res) => {
//     let code = req.query.code
//     let appid = 'wx5ef14bfd0c624d09'
//     let secret = '7256ba2b1c30e9cb3906d749e958b19f'
//     https.get(`https://api.weixin.qq.com/sns/jscode2session?appid=${appid}&secret=${secret}&js_code=${code}&grant_type=authorization_code`, (ret) => {
//     ret.on('data', (ret) => {
//         ret = JSON.parse(ret.toString())
//         let openid = ret.openid
//         if(!openid){
//          res.send({errorMsg: ret.errMsg || '获取openid错误'})   
//         }else{
//             //
//             let queryMember = `select * from member where openId ='${openid}'`
//             SQLHelper(queryMember).then(membersRet =>{
//                 if(membersRet.length){//用户已经存在
//                     res.send(membersRet[0])
//                 }else{
//                     SQLHelper(`INSERT INTO member (openId) VALUES('${openid}')`).then(newMember => {
//                       SQLHelper(sql).then(newMember =>{
//                         res.end(newMember[0])

//                       })  
//                     })
                    
//                 }
//             })
//         }
        
//     });
// }).on('error', (e) => {
//         console.error(e)
//         res.send({errorMsg:'获取openid错误'})
//     });
// })
// // //修改用户信息
// app.put('/wx/member',(req,res) => {
//     let userInfo = req.body
//     SQLHelper(`
//     update member
//     set nickName = '${userInfo.nickName}',avatarUrl= '${userInfo.avatarUrl}'
//     where _id = ${userInfo._id}
//     `).then(ret => {
//         console.log(ret)
//         res.send({})
//     })
// })
// //获取收获地址列表
// app.get('/wx/address',(req,res) =>{
//     if(req.query.memberId){
//     SQLHelper(`
//     select * from address where state = 1 && memberId = ${req.query.memberId}
//     `).then(ret => {
//         res.send(ret)
//         })
//     }else{
//         res.send({errorMsg:"请传入memberId"})
//     }
// })

// app.post('/wx/address',(req,res) =>{
//     if(req.body.memberId && req.body.receiver && req.body.phone && req.body.city){
//         SQLHelper(`
//         INSERT INTO address(state,memberId,receiver,phone,city,area) 
//         values(1,'${req.body.memberId}','${req.body.receiver}','${req.body.phone}','${req.body.city}','${req.body.area || ''}')
//         `).then(ret => {
//             res.send({})
//         })
//     }else{
//         res.send({errMsg:'请传入参数错误'})
//     }
// })


// app.listen(port, () => {
//     console.log(`Example app listening on port ${port}`)
// })
=======
const express = require('express')
var bodyParser = require('body-parser')

const app = express()
const port = 3000
app.use(express.static('www'))
app.use('/uploads',express.static('uploads'))
app.use(bodyParser.json({ limit: '100mb' }));


//设置跨域访问
app.all('*',function(req,res,next) {
  res.header("Access-Control-Allow-Origin","*");
  res.header('Access-Control-Allow-Methods','PUT,GET,POST,DELETE,OPTIONS');
  res.header("Access-Control-Allow-Headers","X-Requested-With");
  res.header('Access-Control-Allow-Headers','Content-Type,token');
  next();
});

const adminRouter = require('./admin')
adminRouter(app)

const wxRouter = require('./wx')
wxRouter(app)

app.listen(port, () => {
  console.log(`Example app listening on port ${port}`)
})
   
>>>>>>> 88e39a9 (完善)
